<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
// ------------------------------------------------------------------------

/**
 * LoggedIn class
 *
 * This class is extended when a page needs to have an authenticated user
 *
 * @package		AchieveIt
 * @subpackage	Core
 * @category	Controller
 * @author		Russ
 */
class LoggedIn extends CI_Controller {

	/* Global data */
	public $data;
	
	/**
	 * Constructor which computes the global data needed
	 *
	 * @access	public
	 */
	function LoggedIn()
	{
        parent::__construct();
		
		$this->load->helper('login_authorization_helper');
		
		/* Check if user is logged in */
		if(!isLoggedIn($this->session->all_userdata()))
		{
			$this->session->set_flashdata('notice', 'You need to be logged in to access this page');
			$this->load->helper('url');
			redirect('/home');
		}
		
		$this->load->model(array('User_model'));
		
		/* Update last online activity */
		$userData = $this->session->all_userdata();
		$this->User_model->update_last_online($userData['id']);
		
		/* Set user data */
		$this->data['global_userData'] = $userData;
		
		/* Check if there is a notice and set it */
		if ($this->session->flashdata('notice') != '')
            $this->data['notice'] = $this->session->flashdata('notice');
    }
	
}
?>